use crate::{ToError, ApiError, ApiResult};

/// bcrypt加密
pub fn hash<P: AsRef<[u8]>>(password: P) -> ApiResult<String> {
    bcrypt::hash(password, bcrypt::DEFAULT_COST).to_err(|| ApiError::Biz("bcrypt加密错误".into()))
}

/// bcrypt验证
pub fn verify<P: AsRef<[u8]>>(password: P, hash: &str) -> ApiResult<bool> {
    bcrypt::verify(password, hash).to_err(|| ApiError::Biz("bcrypt验证错误".into()))
}
